﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Foothill.Common;
using Foothill.Model;

namespace Foothill.Service.AdService
{
    public class CategoryStats
    {
        private IList<StatsItem> _transmissionTypeStats;
        private IList<StatsItem> _listingTypeStats;
        private IList<StatsItem> _vehicleConditionStats;
        private IList<StatsItem> _cityStats;

        public CategoryStats()
        {
            _transmissionTypeStats = new List<StatsItem>();
            _listingTypeStats = new List<StatsItem>();
            _vehicleConditionStats = new List<StatsItem>();
            _cityStats = new List<StatsItem>();
        }

        public int GetCount(AdListCategory category, int idValue)
        {
            IList<StatsItem> list = GetCategoryStatsList(category);

            StatsItem statsItem = list.FirstOrDefault(p => p.GroupId == idValue);

            return statsItem != null ? statsItem.Count : 0;
        }

        public void SaveCategoryStats(AdListCategory category, IList<StatsItem> statsList)
        {
            IList<StatsItem> list = GetCategoryStatsList(category);
            list = statsList;
        }

        private IList<StatsItem> GetCategoryStatsList(AdListCategory category)
        {
            switch (category)
            {
                case AdListCategory.City:
                    return _cityStats;
                case AdListCategory.Condition:
                    return _vehicleConditionStats;
                case AdListCategory.ListingType:
                    return _listingTypeStats;
                case AdListCategory.TransmissionType:
                    return _transmissionTypeStats;
                default:
                    return _transmissionTypeStats;
            }
        }
    }
}
